package com.csbaic.web.advice;

import com.javaobj.common.exception.BizRuntimeException;
import com.javaobj.common.result.Result;
import com.javaobj.common.result.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@ControllerAdvice
@RestControllerAdvice
public class ExceptionAdvice     {


    @ExceptionHandler({BizRuntimeException.class})
    @ResponseBody
    public Result handleBizException(BizRuntimeException ex){
        log.error("biz-ex", ex);
        return Result.error(ex.getCode(), ex.getMessage(), ex.getData());
    }


    @ExceptionHandler({Exception.class})
    @ResponseBody
    public Result handleBizException(Exception ex){
        log.error("ex", ex);
        return Result.error(ResultCode.ERROR.getCode(), ex.getMessage());
    }


}
